{include file="public/header"}
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
        <div class="layui-form-item">
          <label class="layui-form-label">导航类型</label>
          <div class="layui-input-inline">
            <select name="nav_type">
              <option value="0">请选择类型</option>
              {volist name="$nav_type" id="nav" key="k"}
                <option value="{$k}">{$nav}</option>
              {/volist}
            </select>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">上级导航</label>
          <div class="layui-input-inline">
            <select name="parent_id">
              <option value="0">作为顶级导航</option>
              {volist name="nav_list" id="vo"}
                <option value="{$vo.id}" {eq name="$parent_id" value="$vo.id"} selected{/eq}>{$vo.str|raw}{$vo.name}</option>
              {/volist}
            </select>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">名称</label>
          <div class="layui-input-inline">
            <input name="name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" type="text" />
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">英文名称</label>
          <div class="layui-input-inline">
            <input name="e_name" placeholder="请输入" autocomplete="off" class="layui-input" type="text" />
          </div>
          <div class="layui-form-mid layui-word-aux">没有，请留空</div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">跳转链接</label>
          <div class="layui-input-block">
            <input name="linkurl" placeholder="请输入跳转链接，没有请留空" autocomplete="off" class="layui-input" type="text" />
          </div>
        </div>
        <div class="layui-upload" id="upload-thumb">
          <label class="layui-form-label">缩略图</label>
          <button type="button" class="layui-btn" id="thumb">上传图片</button>
          <div class="layui-upload-list">
            <label class="layui-form-label"></label>
            <img class="layui-upload-img" id="demo1" width="100" />
          </div>
          <label class="layui-form-label"></label>
          <p id="demoText"></p>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">关键词</label>
          <div class="layui-input-block">
            <input name="keywords" placeholder="请输入关键词，没有请留空" autocomplete="off" class="layui-input" type="text" />
          </div>
        </div>
        <div class="layui-form-item layui-form-text">
          <label class="layui-form-label">导航描述</label>
          <div class="layui-input-block">
            <input name="description" placeholder="请输入" class="layui-input" type="text" />
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">排序</label>
          <div class="layui-input-inline">
            <input name="sort" placeholder="请输入，例如99" class="layui-input" type="text" value="{$sort}">
          </div>
          <div class="layui-form-mid layui-word-aux">菜单排序排放，数值越小越靠前</div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">状态</label>
          <div class="layui-input-block">
            <div class="layui-input-inline">
              <input type="checkbox" lay-skin="switch" lay-filter="status" lay-text="显示|隐藏" checked />
            </div>
          </div>
        </div>
        <div class="layui-form-item layui-hide">
          <input type="hidden" name="thumb_url" id="thumb_url" />
          <input type="hidden" name="status" id="status" value="1" />
          <input type="button" lay-submit lay-filter="Lay-app-form-submit" id="Lay-app-form-submit" value="添加">
        </div>
      </div>
    </div>
  </div>
</div>
<script>
  layui.use(['layer', 'form', 'upload'], function() {
    var $ = layui.$
            ,upload = layui.upload
            ,form = layui.form
            ,layer = layui.layer;

    var uploadInst = upload.render({
      elem: '#thumb'
      ,url: "{:url('uploadFile/UploadThumb')}"
      ,data: {path: 'thumb'}
      ,done: function(res){
        if(res.code == 0) {
          layer.msg(res.msg);
          $('#demo1').attr('src',res.data.thumb_path);
          $('#thumb_url').val(res.data.thumb_path);
        } else{
          return layer.msg(res.msg);
        }
      }
      , error: function(){
        var demoText = $('#demoText');
        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
        demoText.find('.demo-reload').on('click', function(){
          uploadInst.upload();
        });
      }
    });
    // 监听开关事件
    form.on('switch(status)', function(obj){
      var sta;
      if (obj.elem.checked == true){
        sta = 1;
      } else if(obj.elem.checked == false){
        sta = 0;
      }
      $("#status").val(sta);
    });
  });
</script>
{include file="public/footer"}